package live.ifox.stage;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

import live.ifox.factory.Entry;
import live.ifox.factory.ID;
import live.ifox.factory.Url;

public class MainActivity extends AppCompatActivity {

    Button btn_schedule, btn_position;
    Button btn_journal;
    Button btn_assembleLog, btn_browser;
    Button btn_parlor;
    int level;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_schedule = findViewById(R.id.btn_schedule);
        btn_schedule.setOnClickListener(view ->
                startActivity(new Intent(this,
                        StageViewActivity.class)
                        .putExtra("entry", Entry.Schedule)
                        .putExtra("baseUrl", Url.Schedule)));

        btn_position = findViewById(R.id.btn_position);
        btn_position.setOnClickListener(view ->
                startActivity(new Intent(this,
                        PositionActivity.class)));

        btn_assembleLog = findViewById(R.id.btn_assembleLog);
        btn_assembleLog.setOnClickListener(view ->
                startActivity(new Intent(this,
                        StageViewActivity.class)
                        .putExtra("entry", Entry.AssembleLog)
                        .putExtra("baseUrl", Url.AssembleLog)));

        btn_browser = findViewById(R.id.btn_browser);
        btn_browser.setOnClickListener(view -> {
            startActivity(new Intent(this,
                    BrowserActivity.class));
        });

        btn_parlor = findViewById(R.id.btn_parlor);
        btn_parlor.setOnClickListener(view ->
                startActivity(new Intent(this,
                        StageViewActivity.class)
                        .putExtra("entry", Entry.Parlor)
                        .putExtra("baseUrl", Url.Parlor)));

        btn_journal = findViewById(R.id.btn_journal);
        btn_journal.setOnClickListener(view -> {
            startActivity(new Intent(this,
                    StageViewActivity.class)
                    .putExtra("entry", Entry.Journal)
                    .putExtra("baseUrl", Url.Journal));
        });

        // 隐式启动 ，intent-filter
        // startActivity(new Intent("app_systemInfo"));

        level = getIntent().getIntExtra("level", 0);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, ID.ACTION_PORTAL, 0, "官网");
        menu.add(0, ID.ACTION_ABOUT, 1, "关于...");
        menu.add(0, ID.CHANGE_LOG, 2, "更新日志");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case ID.ACTION_PORTAL:
                startActivity(new Intent()
                        .setAction(Intent.ACTION_VIEW)
                        .setData(Uri.parse(Url.Portal)));
                return true;
            case ID.ACTION_ABOUT:
                startActivity(new Intent(this,
                        AboutActivity.class));
                return true;
            case ID.CHANGE_LOG:
                startActivity(new Intent(this,
                        ChangeLogActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}